package com.study.demo.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.study.demo.model.StudentInfo;
import com.study.demo.service.StudentService;

@Controller
@RequestMapping("/demo")
public class StudentController {
	private static Logger LOGGER = LoggerFactory.getLogger(StudentController.class);
	
	@Autowired
	private StudentService studentService;
	
	@RequestMapping("/getStudentById")
	@ResponseBody
	public void getStudentById(Integer id,HttpServletRequest req,HttpServletResponse resp){
		LOGGER.info("###query id ={}",id);
		if(id <= 0){
			//TODO
			return;
		}
		StudentInfo info = studentService.queryById(id);
		if(info == null){
			LOGGER.info("student 1 not find");
			//TODO
			return;
		}
		LOGGER.info("find student info ={}",info.toString());
		try {
			PrintWriter write = resp.getWriter();
			write.write(info.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	
	
	
	
}
